{% extends "base.html" %}

{% comment %}
Copyright 2012 Google Inc.  All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License.  You may obtain a copy
of the License at: http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distrib-
uted under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied.  See the License for
specific language governing permissions and limitations under the License.
{% endcomment %}

{% block content %}
<script src="//maps.google.com/maps/api/js?sensor=false"></script>
<script src="{{root}}/.static/map_review.js"></script>
<script type="text/javascript">
  setGlobals({{reports_json|safe}}, {{params_json|safe}});
</script>

<h2>Review Crowd Reports: '{{map.title}}' (map ID: {{map.id}})</h2>

<form method="post" id="review-form">
  {{xsrf_tag|safe}}
  <input type="hidden" name="count" id="count" value="{{count}}">
  <input type="hidden" name="skip" id="skip" value="{{skip}}">
  <input type="hidden" name="topic" id="topic" value="{{topic_id}}">
  <input type="hidden" name="hidden" id="hidden" value="{{hidden}}">
  <input type="hidden" name="reviewed" id="reviewed" value="{{reviewed}}">

  <p>
  <h3>Filters</h3>
  <table>
    <tr>
      <td>Keywords:</td>
      <td><input type="text" name="query" id="query" value="{{query}}"/></td>
      <td><input type="button" value="Go" onclick="reload()"/></td>
    </tr>
    <tr>
      <td>ID:</td>
      <td><input type="text" name="id" id="id" value="{{id}}"/></td>
      <td><input type="button" value="Go" onclick="reload()"/></td>
    </tr>
    <tr>
      <td>Author:</td>
      <td><input type="text" name="author" id="author" value="{{author}}"/></td>
      <td><input type="button" value="Go" onclick="reload()"/></td>
    </tr>
    <tr>
      <td>Topic:</td>
      <td colspan=2>
        {% if topic_id %}
          <a href="#" onclick="reload({'topic': '', 'skip': '0'})">All topics</a>
        {% else %}
          All topics
        {% endif %} |
        {% for tid in topic_ids %}
          {% if tid == topic_id %}
            {{tid}}
          {% else %}
            <a href="#" onclick="reload({'topic': '{{tid}}', 'skip': '0'})">{{tid}}</a>
          {% endif %}
          {% if not forloop.last %} | {% endif %}
        {% endfor %}
      </td>
    </tr>
    <tr>
      <td>Hidden:</td>
      <td colspan=2>
        {% if hidden %}
          <a href="#" onclick="reload({'hidden': '', 'skip': '0'})">All</a> | Hidden only
        {% else %}
          All | <a href="#" onclick="reload({'hidden': 'true', 'skip': '0'})">Hidden only</a>
        {% endif %}
      </td>
    </tr>
    <tr>
      <td>Review status:</td>
      <td colspan=2>
        {% if reviewed %}
          All | <a href="#" onclick="reload({'reviewed': '', 'skip': '0'})">Unreviewed only</a>
        {% else %}
          <a href="#" onclick="reload({'reviewed': 'true', 'skip': '0'})">All</a> | Unreviewed only
        {% endif %}
      </td>
    </tr>
  </table>
  </p>
  <p>
  <h3>Reviewing crowd reports {{first}}&ndash;{{last}}
    {% if prev_url %}
      (<a href="{{prev_url}}">previous page</a>)
    {% endif %}
    {% if next_url %}
      (<a href="{{next_url}}">next page</a>)
    {% endif %}
  </h3>
  <table class="cm-crowd-reports">
    <tr>
      <td width="1%" class="cm-plain"></td>
      <td width="1%" class="cm-plain" title="accept">a</td>
      <td width="1%" class="cm-plain" title="downvote (-1000)">d</td>
      <td width="1%" class="cm-plain" title="upvote (+1000)">u</td>
      <th width="1%">Updated</td>
      <th width="32%">Answers</td>
      <th width="60%">Text</td>
      <th width="1%">Votes</td>
      <th width="1%">Author</td>
      <th width="1%">Link</td>
    </tr>
    {% for report in reports %}
    <tr class="cm-crowd-report" id="report-{{forloop.counter}}">
      <td class="cm-caret" id="caret-{{forloop.counter}}"></td>
      <td class="cm-checkbox">
        <input name="accept" type="checkbox"
               id="report-{{forloop.counter}}-accept" title="accept"
               value="{{report.id}}"
               onclick="updateRow({{forloop.counter}}, 'accept')">
      </td>
      <td class="cm-checkbox">
        <input name="downvote" type="checkbox"
               id="report-{{forloop.counter}}-downvote" title="downvote (-1000)"
               value="{{report.id}}"
               onclick="updateRow({{forloop.counter}}, 'downvote')">
      </td>
      <td class="cm-checkbox">
        <input name="upvote" type="checkbox"
               id="report-{{forloop.counter}}-upvote" title="upvote (+1000)"
               value="{{report.id}}"
               onclick="updateRow({{forloop.counter}}, 'upvote')">
      </td>
      <td class="cm-date">{{report.updated}}</td>
      <td class="cm-answers">{{report.answers}}</td>
      <td class="cm-text">{{report.text}}</td>
      <td class="cm-votes">{{report.votes}}</td>
      <td class="cm-author">{{report.author}}</td>
      <td class="cm-link">
        <a href="{{report.url}}" target="_blank" title="{{report.id}}"
            id="link-{{forloop.counter}}">view map</a>
      </td>
    </tr>
    {% endfor %}
  </table>
  </p>
  <input type="submit" value="Process the selected items" class="cm-button cm-submit">
  </form>
  <h3>Map of crowd reports</h3>
  <div id="map-canvas" style="width:100%; min-height:400px"></div>
  <br/>
{% endblock %}
